package com.tanhua.server.controller;

import com.tanhua.model.vo.NearUserVo;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.TodayBest;
import com.tanhua.server.serivce.TanhuaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/tanhua")
public class TanhuaController {

    @Autowired
    private TanhuaService tanhuaService;

    /**
     * 查询今日佳人
     *   GET    /todayBest
     *   响应数据  TodayBest
     */
    @GetMapping("/todayBest")
    public ResponseEntity todayBest() {
        TodayBest vo = tanhuaService.todayBest();
        return ResponseEntity.ok(vo);
    }

    /**
     * 查询首页推荐
     *  GET /recommendation?page=1&pagesize=10
     *  请求参数：
     *    Query：page，pagesize
     *  响应数据
     *    PageResult分页对象，内部封装List<TodayBest>
     */
    @GetMapping("/recommendation")
    public ResponseEntity recommendation(@RequestParam(defaultValue = "1") Integer page,
                                         @RequestParam(defaultValue = "10") Integer pagesize) {
        //调用service查询
        PageResult vo = tanhuaService.recommendation(page,pagesize);
        //返回
        return ResponseEntity.ok(vo);
    }

    /**
     * 查看佳人信息
     *   GET        /{id}/personalInfo
     *   返回值  TodayBest
     */
    @GetMapping("/{id}/personalInfo")
    public ResponseEntity personalInfo(@PathVariable("id") Long userId) {
        TodayBest vo = tanhuaService.personalInfo(userId);
        return ResponseEntity.ok(vo);
    }



    /**
     * 查看陌生人问题
     *   GET  /strangerQuestions
     *   参数：userId=查看的用户id
     *  返回值：
     *    陌生人问题内容
     */
    @GetMapping("/strangerQuestions")
    public ResponseEntity strangerQuestions(Long userId) {
        String content = tanhuaService.strangerQuestions(userId);
        return ResponseEntity.ok(content);
    }


    /**
     * 回复陌生人消息
     *  POST        /strangerQuestions
     *  参数（body）：
     *      userId，reply
     */
    @PostMapping("/strangerQuestions")
    public ResponseEntity strangerQuestions(@RequestBody Map map) {
        //获取参数
        String str = map.get("userId").toString();
        Long userId = Long.valueOf(str);
        String reply = map.get("reply").toString();
        //调用service
        tanhuaService.reply(userId,reply);
        return ResponseEntity.ok(null);
    }


    /**
     * 搜附近
     *      GET     /search
     *      参数：
     *          gender：性别
     *          distance：距离
     *      返回值
     *          List<NearUserVo>
     */
    @GetMapping("/search")
    public ResponseEntity search(String gender,String distance) {
        List<NearUserVo> list =  tanhuaService.search(gender,distance);
        return ResponseEntity.ok(list);
    }

}
